package com.chen.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(value = "/t7")
public class TestHttpServletResponse extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 响应行 一般设置状态码
        resp.setStatus(200);
        String info = "ASD";
        // 响应头

        // 一般设置 Content-Type 和 Content-Length
        // Content-Type 告知浏览以什么的样子的的方式来解析响应的内容
        //  Content-Length 设置返回的相依数据的字节数  开发者查询是否有返回数据的丢失
        resp.setContentType("text/css");
        resp.setContentLength(info.getBytes().length);
        // 响应体 通过获取输出流来向
        PrintWriter writer = resp.getWriter();
        writer.write(info);
    }
}
